import yagmail
import requests
mail_address = "newrain_wang@163.com"
mail_address1 = "18794762984@163.com"
mail_host = "smtp.163.com"
mail_port = 465
mail_password = "ZFWFCRWKIQOQPAMM"
def sendmail(to_user: list, 
             subject: str, 
             text: str,
             att=None):
    if isinstance(to_user, (str, list)) and isinstance(subject, str) and isinstance(text, str):
        ## 初始化邮件服务器对象
        smtp = yagmail.SMTP(user=mail_address,
                     password=mail_password,
                     host=mail_host,
                     port=mail_port,
                     smtp_ssl=True)
        smtp.send(to=to_user, subject=subject, contents=text, attachments=att)
    else:
        raise TypeError("参数类型错误")
data = '''
一条大运河，半部华夏史。今年是中国大运河申遗成功十周年。6月23日，“何以中国·运载千秋”网络主题采访活动从扬州出发，探寻大运河作为文化根脉、生态绿脉、经济动脉所散发的独特魅力。
“申遗成功不仅是获得一项荣誉，更是告诉世界，我们有能力把大运河遗产保护好、利用好。”江苏省文史研究馆馆员、原大运河联合申遗办公室主任顾风说，“我们要让大运河长期发挥作用，保持它活态的特征”。
'''
r = requests.get(url='https://pics0.baidu.com/feed/91ef76c6a7efce1baea8756d2a40bed0b58f65b1.jpeg@f_auto?token=0a5d8d1f8315f342b5429eabf0e35222')
if r.status_code == 200:
    with open(file="/root/qianfeng/day4./yunhe.jpg", mode='wb') as f:
        f.write(r.content)
sendmail(to_user=mail_address1, subject="python实训", text=data,att="/root/qianfeng/day4./yunhe.jpg")